use std::rc::Rc;
use rayon::prelude::*;

struct LinkData {
    data_f64: Vec<f64>,
    data_i32: Vec<i32>
}
impl Default for LinkData{
    fn default() -> Self {
        LinkData{
            data_f64: Vec::new(),
            data_i32: Vec::new()
        }
    }
}
struct Link{
    data: Rc<LinkData>,
    newdata: Rc<LinkData>
}
impl Link {
    pub fn send(&mut self, data: Box<LinkData>) {
        self.newdata = data.into();
    }
    pub fn recv(&self) -> Rc<LinkData> {
        self.data.clone()
    }
    pub fn trans(&mut self) {
        self.data = self.newdata.clone();
    }
}
trait SubSystem {
    fn next_state(&mut self, timestep: f64);
    fn initial(&mut self);
}

struct Config{
    timestep: f64,
    endtime: f64,
}

struct System {
    subsystems: Vec<Box<dyn SubSystem>>,
    links: Vec<Link>,
    config: Config,
    time: f64,
}

impl System {
    fn start(&mut self) {
        self.subsystems.par_iter().for_each(|&x| x.next_state(self.config.timestep))
    }
}